/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace Avro.IO { /// /// Defines the interface for a class that provies low-level support for serializing Avro /// values. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1715:Identifiers should have correct prefix", Justification = "Maintain public API")] public interface Encoder { /// /// Writes a null value. /// void WriteNull(); /// /// Writes a boolean value. /// /// Value to write. void WriteBoolean(bool value); /// /// Writes an int value. /// /// Value to write. void WriteInt(int value); /// /// Writes a long value. /// /// Value to write. void WriteLong(long value); /// /// Writes a float value. /// /// Value to write. void WriteFloat(float value); /// /// Writes a double value. /// /// Value to write. void WriteDouble(double value); /// /// Writes a byte string. /// /// Value to write. void WriteBytes(byte[] value); /// /// Writes a byte string. /// /// The byte[] to be read (fully or partially) /// The offset from the beginning of the byte[] to start writing /// The length of the data to be read from the byte[]. void WriteBytes(byte[] value, int offset, int length); /// /// Writes an Unicode string. /// /// Value to write. void WriteString(string value); /// /// Writes an enumeration. /// /// Value to write. void WriteEnum(int value); /// /// Call this method before writing a batch of items in an array or a map. /// /// Number of calls to follow. void SetItemCount(long value); /// /// Start a new item of an array or map. See for usage /// information. /// void StartItem(); /// /// Call this method to start writing an array. When starting to serialize an array, call /// . Then, before writing any data for any item call /// followed by a sequence of and /// the item itself. The number of should match the number specified /// in . When actually writing the data of the item, you can /// call any method (e.g., ). When all /// items of the array have been written, call . /// /// As an example, let's say you want to write an array of records, the record consisting /// of an Long field and a Boolean field. Your code would look something like this: /// /// out.WriteArrayStart(); /// out.SetItemCount(list.Count); /// foreach (var r in list) /// { /// out.StartItem(); /// out.WriteLong(r.LongField); /// out.WriteBoolean(r.BoolField); /// } /// out.WriteArrayEnd(); /// /// /// void WriteArrayStart(); /// /// Call this method to finish writing an array. See for usage /// information. /// void WriteArrayEnd(); /// /// Call this to start a new map. See for details on usage. /// /// As an example of usage, let's say you want to write a map of records, the record /// consisting of an Long field and a Boolean field. Your code would look something like /// this: /// /// out.WriteMapStart(); /// out.SetItemCount(dictionary.Count); /// foreach (var entry in dictionary) /// { /// out.StartItem(); /// out.WriteString(entry.Key); /// out.writeLong(entry.Value.LongField); /// out.writeBoolean(entry.Value.BoolField); /// } /// out.WriteMapEnd(); /// /// /// void WriteMapStart(); /// /// Call this method to terminate the inner-most, currently-opened map. See /// for more details. /// void WriteMapEnd(); /// /// Call this method to write the tag of a union. /// /// As an example of usage, let's say you want to write a union, whose second branch is a /// record consisting of an Long field and a Boolean field. Your code would look something /// like this: /// /// out.WriteIndex(1); /// out.WriteLong(record.LongField); /// out.WriteBoolean(record.BoolField); /// /// /// /// void WriteUnionIndex(int value); /// /// Writes a fixed value. /// /// The contents to write. void WriteFixed(byte[] data); /// /// Writes a fixed value. /// /// Contents to write. /// Position within data where the contents start. /// Number of bytes to write. void WriteFixed(byte[] data, int start, int len); } }