TextOutput.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2005 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <hwbinder/TextOutput.h>
  17. #include <hwbinder/Debug.h>
  18. #include <utils/String8.h>
  19. #include <utils/String16.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. namespace android {
  24. namespace hardware {
  25. // ---------------------------------------------------------------------------
  26. TextOutput::TextOutput() {
  27. }
  28. TextOutput::~TextOutput() {
  29. }
  30. // ---------------------------------------------------------------------------
  31. static void textOutputPrinter(void* cookie, const char* txt)
  32. {
  33. ((TextOutput*)cookie)->print(txt, strlen(txt));
  34. }
  35. TextOutput& operator<<(TextOutput& to, const TypeCode& val)
  36. {
  37. printTypeCode(val.typeCode(), textOutputPrinter, (void*)&to);
  38. return to;
  39. }
  40. HexDump::HexDump(const void *buf, size_t size, size_t bytesPerLine)
  41. : mBuffer(buf)
  42. , mSize(size)
  43. , mBytesPerLine(bytesPerLine)
  44. , mSingleLineCutoff(16)
  45. , mAlignment(4)
  46. , mCArrayStyle(false)
  47. {
  48. if (bytesPerLine >= 16) mAlignment = 4;
  49. else if (bytesPerLine >= 8) mAlignment = 2;
  50. else mAlignment = 1;
  51. }
  52. TextOutput& operator<<(TextOutput& to, const HexDump& val)
  53. {
  54. printHexData(0, val.buffer(), val.size(), val.bytesPerLine(),
  55. val.singleLineCutoff(), val.alignment(), val.carrayStyle(),
  56. textOutputPrinter, (void*)&to);
  57. return to;
  58. }
  59. }; // namespace hardware
  60. }; // namespace android