… | |
… | |
501 | =item json => L<JSON>, L<JSON::PP> or L<JSON::XS> object |
501 | =item json => L<JSON>, L<JSON::PP> or L<JSON::XS> object |
502 | |
502 | |
503 | This is the json coder object used by the C<json> read and write types. |
503 | This is the json coder object used by the C<json> read and write types. |
504 | |
504 | |
505 | If you don't supply it, then AnyEvent::Handle will create and use a |
505 | If you don't supply it, then AnyEvent::Handle will create and use a |
506 | suitable one (on demand), which will write and expect UTF-8 encoded JSON |
506 | suitable one (on demand), which will write and expect UTF-8 encoded |
|
|
507 | JSON texts (either using L<JSON::XS> or L<JSON>). The written texts are |
|
|
508 | guaranteed not to contain any newline character. |
|
|
509 | |
|
|
510 | For security reasons, this encoder will likely I<not> handle numbers and |
|
|
511 | strings, only arrays and objects/hashes. The reason is that originally |
|
|
512 | JSON was self-delimited, but Dougles Crockford thought it was a splendid |
|
|
513 | idea to redefine JSON incompatibly, so this is no longer true. |
|
|
514 | |
|
|
515 | For protocols that used back-to-back JSON texts, this might lead to |
|
|
516 | run-ins, where two or more JSON texts will be interpreted as one JSON |
507 | texts. |
517 | text. |
|
|
518 | |
|
|
519 | For this reason, if the default encoder uses L<JSON::XS>, it will default |
|
|
520 | to not allowing anything but arrays and objects/hashes, at least for the |
|
|
521 | forseeable future (it will change at some point). This might or might not |
|
|
522 | be true for the L<JSON> module, so this might cause a security issue. |
|
|
523 | |
|
|
524 | If you depend on either behaviour, you should create your own json object |
|
|
525 | and pass it in explicitly. |
508 | |
526 | |
509 | =item cbor => L<CBOR::XS> object |
527 | =item cbor => L<CBOR::XS> object |
510 | |
528 | |
511 | This is the cbor coder object used by the C<cbor> read and write types. |
529 | This is the cbor coder object used by the C<cbor> read and write types. |
512 | |
530 | |
513 | If you don't supply it, then AnyEvent::Handle will create and use a |
531 | If you don't supply it, then AnyEvent::Handle will create and use a |
514 | suitable one (on demand), which will write CBOR without using extensions, |
532 | suitable one (on demand), which will write CBOR without using extensions, |
515 | if possible. texts. |
533 | if possible. |
516 | |
534 | |
517 | Note that you are responsible to depend on the L<CBOR::XS> module if you |
535 | Note that you are responsible to depend on the L<CBOR::XS> module if you |
518 | want to use this functionality, as AnyEvent does not have a dependency on |
536 | want to use this functionality, as AnyEvent does not have a dependency on |
519 | it itself. |
537 | it itself. |
520 | |
538 | |
… | |
… | |
1054 | |
1072 | |
1055 | Encodes the given hash or array reference into a JSON object. Unless you |
1073 | Encodes the given hash or array reference into a JSON object. Unless you |
1056 | provide your own JSON object, this means it will be encoded to JSON text |
1074 | provide your own JSON object, this means it will be encoded to JSON text |
1057 | in UTF-8. |
1075 | in UTF-8. |
1058 | |
1076 | |
|
|
1077 | The default encoder might or might not handle every type of JSON value - |
|
|
1078 | it might be limited to arrays and objects for security reasons. See the |
|
|
1079 | C<json> constructor attribute for more details. |
|
|
1080 | |
1059 | JSON objects (and arrays) are self-delimiting, so you can write JSON at |
1081 | JSON objects (and arrays) are self-delimiting, so if you only use arrays |
1060 | one end of a handle and read them at the other end without using any |
1082 | and hashes, you can write JSON at one end of a handle and read them at the |
1061 | additional framing. |
1083 | other end without using any additional framing. |
1062 | |
1084 | |
1063 | The generated JSON text is guaranteed not to contain any newlines: While |
1085 | The JSON text generated by the default encoder is guaranteed not to |
1064 | this module doesn't need delimiters after or between JSON texts to be |
1086 | contain any newlines: While this module doesn't need delimiters after or |
1065 | able to read them, many other languages depend on that. |
1087 | between JSON texts to be able to read them, many other languages depend on |
|
|
1088 | them. |
1066 | |
1089 | |
1067 | A simple RPC protocol that interoperates easily with other languages is |
1090 | A simple RPC protocol that interoperates easily with other languages is |
1068 | to send JSON arrays (or objects, although arrays are usually the better |
1091 | to send JSON arrays (or objects, although arrays are usually the better |
1069 | choice as they mimic how function argument passing works) and a newline |
1092 | choice as they mimic how function argument passing works) and a newline |
1070 | after each JSON text: |
1093 | after each JSON text: |