Method encode_value()
- Method
encode_value
string(8bit)encode_value(mixedvalue,Codec|voidcodec)
string(8bit)encode_value(mixedvalue,Codec|voidcodec,String.Buffertrace)
string(8bit)encode_value(mixedvalue,Codec|voidcodec,int(0..)debug)- Description
Code a value into a string.
- Parameter
value Value to encode.
- Parameter
codec Codec to use when encoding objects and programs.
- Parameter
trace String.Buffer to contain a readable dump of the value.
- Parameter
debug Debug level. Only available when the runtime has been compiled --with-rtl-debug.
This function takes a value, and converts it to a string. This string can then be saved, sent to another Pike process, packed or used in any way you like. When you want your value back you simply send this string to decode_value() and it will return the value you encoded.
Almost any value can be coded, mappings, floats, arrays, circular structures etc.
If
codecis specified, it's used as the codec for the encode. If none is specified, then one is instantiated throughmaster()->Encoder(). As a compatibility fallback, the master itself is used if it has noEncoderclass.If
returns UNDEFINED for an object,codec->nameof(o)val = o->encode_object(o)will be called. The returned value will be passed too->decode_object(o, val)when the object is decoded.- Note
When only simple types like int, floats, strings, mappings, multisets and arrays are encoded, the produced string is very portable between pike versions. It can at least be read by any later version.
The portability when objects, programs and functions are involved depends mostly on the codec. If the byte code is encoded, i.e. when Pike programs are actually dumped in full, then the string can probably only be read by the same pike version.
- See also